import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    redirect: "/home",
  },
  {
    path: "/home",
    component: () => import("../views/Home.vue"),
    children:[
      {
        path:"/home",
        redirect:"/home/movies",
      },
      {
        path:"/home/movies",
        component:()=> import("../views/home/movies.vue"),
        children:[
          {
            path:"/home/movies",
            redirect:"/home/movies/hot",
          },
          {
            path:"/home/movies/hot",
            component:()=> import("../components/home/MyList.vue"),
          },
          {
            path:"/home/movies/cinema",
            component:()=> import("../components/home/Cinema.vue"),
          }
          ,
          {
            path:"/home/movies/wait",
            component:()=> import("../components/home/Wait.vue"),
          },
          {
            path:"/home/movies/classic",
            component:()=> import("../components/home/Classic.vue"),
          }
        ],
        meta: {
          title: "电影",
        },
      },

      {
        path:"/home/video",
        component:()=> import("../views/home/video.vue"),
        meta: {
          title: "视频",
        },
      },
      {
        path:"/home/minivideo",
        component:()=> import("../views/home/minivideo.vue"),
        meta: {
          title: "小视频",
        },
      },
      {
        path:"/home/show",
        component:()=> import("../views/home/show.vue"),
        meta: {
          requireLogin: true,
          title: "演出",
        },
      },
      {
        path:"/home/mine",
        component:()=> import("../views/home/mine.vue"),
        meta: {
          requireLogin: true,
          title: "我的",
        },
      },
    ],
  },
  {
    path: "/city",
    component: () => import("../views/City.vue"),
  },
  {
    path: "/detail/:id",
    component: () => import("../views/Detail.vue"),
    props: true,
  },
  {
    path: "/search",
    component: () => import("../views/Search.vue"),
  },
  {
    path: "*",
    component: () => import("../views/404.vue"),
  },
];




const router = new VueRouter({
  routes,
});


// 全局后置钩子 放路由实例之后
router.afterEach((to) => {
  // ...
  // 改变页面标题
  document.title = to.meta.title || "娱乐看猫眼";
});

const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};

export default router;
